package com.shruijin.wy.aop.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * method 2：通过 aspect 注解实现(AspectJ)
 */
@Aspect
@Component
public class ActionAdvice2 {

    Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    @Pointcut("execution(* com.shruijin.wy.aop..*.*(..))")
    public void pointcut1(){

    }

    @Pointcut("execution(* com.shruijin.wy.aop..*.say(..))")
    public void pointcut2(){

    }

    @Before("pointcut1()")
    public void before(JoinPoint joinPoint){
        LOGGER.info("{} 注解方式，前置通知!",joinPoint.getSignature().getName());
    }

    @After("pointcut1()")
    public void after(JoinPoint joinPoint){
        LOGGER.info("{} 注解方式，后置通知!",joinPoint.getSignature().getName());
    }

    @Around("pointcut2()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        joinPoint.proceed();
        LOGGER.info("{} 注解方式，环置通知!",joinPoint.getSignature().getName());

    }

    @AfterReturning("@annotation(com.shruijin.wy.aop.anno.AdviceAnno)")
    public void afterreturn(JoinPoint joinPoint){
        LOGGER.info("{} 注解方式，添加返回通知!",joinPoint.getSignature().getName());
    }

    @AfterThrowing("execution(void com.shruijin.wy.aop..*.*(..))")
    public void afterthrow(JoinPoint joinPoint){
        LOGGER.info("{} 注解方式，异常通知!",joinPoint.getSignature().getName());
    }

}
